package cn.virens.common.mapper.example;

import cn.virens.common.exception.APIException;
import cn.virens.common.mapper.example.base.AbstractExampleCriteriaCriterion;
import cn.virens.common.mapper.example.util.Util;

@SuppressWarnings("serial")
public class ExampleJoin extends AbstractExampleCriteriaCriterion<ExampleCriteria> {
    private final String table;
    private final String join;

    public ExampleJoin(String join, String table) {
        super(Util.AND, null);

        this.table = table;
        this.join = join;
    }

    public String getTable() {
        return table;
    }

    public String getJoin() {
        return join;
    }

    protected ExampleCriteria addCriterion(String andOr, String condition) throws APIException {
        this.criterionList.add(new ExampleCriteria(andOr, condition));

        return null;
    }

    protected ExampleCriteria addCriterion(String andOr, String condition, Object value) throws APIException {
        if (condition != null && !condition.isEmpty() && value != null && Util.isNotEmpty(value)) {
            this.criterionList.add(new ExampleCriteria(andOr, condition, enumv(value)));
        }

        return null;
    }

    protected ExampleCriteria addCriterion(String andOr, String condition, Object value1, Object value2) throws APIException {
        this.criterionList.add(new ExampleCriteria(andOr, condition, value1, value2));

        return null;
    }

}
